<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<!DOCTYPE>
<html>
	<head>
		<title>微信</title>
		<script src="${basePath}resources/js/Jquery-md5.js"></script>
	</head>
	<body>
		<div class="loading"></div>
		<!-- header -->
		<header class='login_header'>
			<a href="javascript:history.go(-1);" class="top_fh">微信</a>
		</header>
		<!-- header end -->
		
		<div class="page login_page">
			<div class="login_inner">
				<form id="myForm" name="myForm">
					<input type="hidden" id="openId" name="openId" />
			
					<div class="login_tx"><img src="${basePath}resources/js/wechat/images/login_tx.png" alt=""></div>

					<div class="loginPoint"></div>

					<div class="lgin_form">
						<div class='lg_zh'><input id="username" name="username" type="text" placeholder="请输入用户名"></div>
						<div class='lg_ps'><input id="password"  name="password" type="password" placeholder="请输入密码"></div>
						<div class='lg_yzm'><input id="valid"  name="vildCode" type="text" placeholder="请输入验证码"><img id="captchaImage" src="${basePath}authCode" alt=""
							onclick="chageCode()"  ></div>
						<div class="lg_button"><input type="button" value="绑定" class="login_button" style="font-size:1rem;" ></div>
						<!--  <div class="lg_qt"><a href="zhaohuimm.html">忘记密码</a><a href="zhuce.html">还没有帐号？立即注册>></a></div>-->
					</div>
				</form>
			</div>
			<div class="footer_bz">游艺云</div>
		</div>
	</body>
</html>
<script>
function chageCode() {
	$('#captchaImage').attr('src', '${basePath}authCode?abc=' + Math.random());//链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
}

$(function(){

	 $("#openId").val(getCookie('openid'));
	//登录
	$(".lg_button input").on("click", function(){
		var username = $("#username").val();	
		var password = $("#password").val();	
		var vaild = $("#valid").val();

		if(username==null||username==''){
			$(".loginPoint").text("用户名不能为空");
			//alert("用户名不能为空");
		}else if(password==null||password==''){
			$(".loginPoint").text("密码不能为空");
			//alert("密码不能为空");
		}else if(vaild==null||vaild==''){
			$(".loginPoint").text("验证码不能为空");
			//alert("验证码不能为空");
		}else{
			$("#password").val(createPassword(password,password));
			$.ajax({
				url:'${basePath}wechat/login/signin',
				type : 'POST',
				data : $("#myForm").serialize(),
				error: function (response) {
					ViewHelper.func.ajaxWechatErrorMessage(response);
				},
				success: function (ret) {
					if(ret.result) {
						setCookie(username,password,1);
						window.location = "${basePath}wechat/bind/bind/showView";
					}else{
						$(".loginPoint").text(ret.info);

						//alert(ret.info);
					}
				}
			}); 
			
		}
				
	});

});

function setCookie(username ,password,expiredays)
{
	var date=new Date();
	var expiresDays=10;
//将date设置为10天以后的时间
	date.setTime(date.getTime()+expiresDays*24*3600*1000);
//将userId和userName两个cookie设置为10天后过期
	document.cookie="username="+username+"; password="+password+"; expires="+date.toGMTString();

}
//initcookie();
function  initcookie() {
	var strCookie = document.cookie;
//将多cookie切割为多个名/值对
	var username;
	var arrCookie = strCookie.split("; ");
	for (var i = 0; i < arrCookie.length; i++) {
		var arr = arrCookie[i].split("=");
		if ("username" == arr[0]) {
			username=arr[1];
		}
		if ("password" == arr[0]) {
			password=arr[1];
		}
	}
	if(username!=null&&password!=null&&username!=''&&password!=''){
		$("#username").val(username);
		$("#password").val(createPassword(password,password));
		alert(username);
		alert('username='+$("#username").val());
		alert(password);
		alert('password='+$("#password").val());

	/*	$.ajax({
			url:'${basePath}wechat/login/signin',
			type : 'POST',
			data : $("#myForm").serialize(),
			error: function (response) {
				ViewHelper.func.ajaxWechatErrorMessage(response);
			},
			success: function (ret) {
				if(ret.result) {
					window.location = "${basePath}wechat/bind/bind/showView";
				}else{
					$(".loginPoint").text(ret.info);

					//alert(ret.info);
				}
			}
		});*/
	}
}



</script>

